package bucket

import (
	"clouds.lgb24kcs.cn/controllers/bucket/request"
	"clouds.lgb24kcs.cn/errorx"
	"clouds.lgb24kcs.cn/global"
	"clouds.lgb24kcs.cn/models"
	"clouds.lgb24kcs.cn/utils"
	"clouds.lgb24kcs.cn/utils/history"
	"github.com/gin-gonic/gin"
)

type BucketSelect struct {
}

var SelectAPI = BucketSelect{}

func (s *BucketSelect) BucketSelect(c *gin.Context, req request.SelectBucketReq, userId int64) {
	BucketInfo := []models.Storage{}
	tx := global.APP.DB.Where("id=? and userid=?", req.BucketId, userId).Find(&BucketInfo)
	if tx.Error != nil {
		global.APP.Log.Error(tx.Error.Error())
		utils.Fail(c, errorx.BucketSelect, tx.Error.Error())
	} else {
		if err := history.HistoryCreate(userId, c.Request.Method, c.Request.URL.String(), c.Request.Host); err != nil {
			utils.Fail(c, errorx.ObjectSearch, err.Error())
		} else {
			utils.Success(c, 0, BucketInfo)
		}
	}

}
